#include <stdio.h>
#include <string.h>

struct Node{
	int data;
	Node* next;
};

Node* createList()
{
	Node* res=0;
	for(int i=0;i<10;i++)
	{
		Node* tmp=new Node;
		tmp->data=i;
		tmp->next=0;
		if(res==0)
			res=tmp;
		else
		{
			tmp->next=res;
			res=tmp;
		}
	}
	return res;
}
void delList(Node* list)
{
	while(list!=0)
	{
		Node* tmp=list;
		list=list->next;
		delete tmp;
	}
}
Node* revList(Node* list)
{
	if(list==0)
		return 0;
	if(list->next==0)
		return list;
	Node* rlist=revList(list->next);
	list->next->next=list;
	list->next=0;
	return rlist;
}
Node* revList2(Node* list)
{
	Node* lastN=0;
	Node* curN=list;
	while(curN!=0)
	{
		Node* tmp=curN;
		curN=curN->next;
		tmp->next=lastN;
		lastN=tmp;
	}
	return lastN;
}
void printList(Node* list)
{
	while(list!=0)
	{
		printf("%3d ",list->data);
		list=list->next;
	}
	printf("\n");
}

bool match(const char* src,const char* ptn)
{
	if(*ptn=='\0' || *src=='\0')
	{
		return *src==*ptn;
	}
	if(*ptn=='?'|| *src==*ptn)
	{
		return match(src+1,ptn+1);
	}
	if(*ptn=='*')
	{
		do{
			if(match(src++,ptn+1))
				return true;
		}while(*src!=0);
		return *(ptn+1)==0;
	}
	return false;
}
void reveStr(char* src,int n)
{
	if(src==0)
		return;
	//int len=strlen(src);
	int len=n;
	int i=0;
	int j=len-1;
	while(i<j)
	{
		char tmp=src[i];
		src[i]=src[j];
		src[j]=tmp;
		i++;
		j--;
	}
}
void reveSten(char* sten)
{
	if(sten==0)
		return;
	int len=strlen(sten);
		
	reveStr(sten,len);
	int i=0,j=0;
	while(i<len)
	{
		while(i<len && sten[i]==' ')
		{
			i++;
		}
		if(i<len)
		{
			for(j=i;j<len && sten[j]!=' ';j++);
			reveStr(sten+i,j-i);
			i=j+1;
		}
	}
	
}
struct s  
{  int x:3;  
   int y:4;  
   int z:5;  
 double a;  
};
int main()
{
/*	Node* list=createList();*/
/*	*/
/*	printList(list);*/
/*	list=revList(list);*/
/*	printList(list);*/
/*	list=revList2(list);*/
/*	printList(list);*/
/*	delList(list);*/
/*	*/
/*	if(match("src","s**"))*/
/*		printf("true");*/
	char A[]="hello";
	reveStr(A,strlen(A));
	printf("%s\n",A);
	
	char st[]="hello world a";
	reveSten(st);
	printf("%s\n",st);
	
	int a[2][2][3]= { {{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}}; 
	int *ptr=(int *)(&a+1);  
	printf("%d %d\n", *(int*)(a+1), *(ptr-1));
	printf("%p %p\n",a,&a);
	printf("%p %p\n",a+1,&a+1);
	printf("%ld %ld\n",sizeof(s),sizeof(ptr));
	
	return 0;
	
}
